package org.nf.web.servlet;

import cn.hutool.core.util.ReflectUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * @Author czl
 * @Date 2024-05-15
 * 负责调用Controller方法处理请求
 */
public class HandlerInvoke {
    public void invoke(Class<?> controllerClass,HttpServletRequest request , HttpServletResponse response){
        //如果controllerClass实现了Controller接口则返回true
        if(Controller.class.isAssignableFrom(controllerClass)){
            //创建Controller的实例
            Controller controller = (Controller) ReflectUtil.newInstance(controllerClass);
            //调用execute方法处理请求
            controller.execute(request,response);
        }
    }
}
